package com.ruoyi.jjyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjyh.domain.JjyhUsersign;
import com.ruoyi.jjyh.service.IJjyhUsersignService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 签到记录Controller
 * 
 * @author ruoyi
 * @date 2020-12-01
 */
@Controller
@RequestMapping("/jjyh/usersign")
public class JjyhUsersignController extends BaseController
{
    private String prefix = "jjyh/usersign";

    @Autowired
    private IJjyhUsersignService jjyhUsersignService;

    @RequiresPermissions("jjyh:usersign:view")
    @GetMapping()
    public String usersign()
    {
        return prefix + "/usersign";
    }

    /**
     * 查询签到记录列表
     */
    @RequiresPermissions("jjyh:usersign:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JjyhUsersign jjyhUsersign)
    {
        startPage();
        List<JjyhUsersign> list = jjyhUsersignService.selectJjyhUsersignList(jjyhUsersign);
        return getDataTable(list);
    }

    /**
     * 导出签到记录列表
     */
    @RequiresPermissions("jjyh:usersign:export")
    @Log(title = "签到记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JjyhUsersign jjyhUsersign)
    {
        List<JjyhUsersign> list = jjyhUsersignService.selectJjyhUsersignList(jjyhUsersign);
        ExcelUtil<JjyhUsersign> util = new ExcelUtil<JjyhUsersign>(JjyhUsersign.class);
        return util.exportExcel(list, "usersign");
    }

    /**
     * 新增签到记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存签到记录
     */
    @RequiresPermissions("jjyh:usersign:add")
    @Log(title = "签到记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JjyhUsersign jjyhUsersign)
    {
        return toAjax(jjyhUsersignService.insertJjyhUsersign(jjyhUsersign));
    }

    /**
     * 修改签到记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JjyhUsersign jjyhUsersign = jjyhUsersignService.selectJjyhUsersignById(id);
        mmap.put("jjyhUsersign", jjyhUsersign);
        return prefix + "/edit";
    }

    /**
     * 修改保存签到记录
     */
    @RequiresPermissions("jjyh:usersign:edit")
    @Log(title = "签到记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JjyhUsersign jjyhUsersign)
    {
        return toAjax(jjyhUsersignService.updateJjyhUsersign(jjyhUsersign));
    }

    /**
     * 删除签到记录
     */
    @RequiresPermissions("jjyh:usersign:remove")
    @Log(title = "签到记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jjyhUsersignService.deleteJjyhUsersignByIds(ids));
    }
}
